package com.zsk.okhttp;

import java.io.File;
import java.io.IOException;

import okhttp3.Callback;

/**
 * multipart/form-data 提交任务
 * 
 * @author keke
 * @date 2020/04/23
 */
public interface IPostMultiTask {

    /**
     * 同步任务
     * 
     * @param percentListener
     * @return
     * @throws IOException
     */
    ResData run(IPostMultiTask.PercentListener percentListener) throws IOException;

    /**
     * 异步任务
     * 
     * @param callback
     * @param listener
     */
    void run(Callback callback, IPostMultiTask.PercentListener listener);

    /**
     * 添加头
     * 
     * @param name
     * @param value
     * @return
     */
    IPostMultiTask addHeader(String name, String value);

    /**
     * 添加表单
     * 
     * @param name
     * @param value
     * @return
     */
    IPostMultiTask addFormDataPart(String name, String value);

    /**
     * 添加文件
     * 
     * @param name
     * @param file
     * @return
     */
    IPostMultiTask addFormDataPart(String name, File file);

    /**
     * 添加url参数
     * 
     * @param name
     * @param value
     * @return
     */
    IPostMultiTask addQueryParam(String name, String value);

    /**
     * 上传进度回调接口
     * 
     * @author keke
     * @date 2020/04/23
     */
    public interface PercentListener {
        /**
         * 上传进度
         * 
         * @param percent
         * @param total
         * @param writed
         * @param done
         */
        void process(int percent, long total, long writed, boolean done);
    }

}
